import {BasicColumn, FormSchema} from '/@/components/Table';
import {
  DicItem,
  getAccountList,
  getAccountNameList,
  getAdminUserNameList
} from "/@/api/system/system";
import {h} from "vue";
import {Badge, Tag} from "ant-design-vue";

export const columns: BasicColumn[] = [
  {
    title: 'ID',
    dataIndex: 'id',
    width: 50,
    align: 'center',
  },
  {
    title: '任务标题',
    dataIndex: 'title',
    width: 250,
    align: 'center',
  },
  {
    title: '任务类型',
    dataIndex: 'task_type_name',
    width: 120,
    align: 'center',
    customRender: ({ record }) => {
      const name = record.task_type_name || '无'
      return h(Tag, { color: 'blue' }, () =>name );
    },
  },
  {
    title: '奖励点数',
    dataIndex: 'reward',
    width: 100,
    align: 'center',
  },
  {
    title: '奖励单位',
    dataIndex: 'reward_unit',
    width: 100,
    align: 'center',
  },
  {
    title: '参加人数',
    dataIndex: 'join_num',
    width: 100,
    align: 'center',
  },
  {
    title: '审核员',
    dataIndex: 'auditor_name',
    width: 100,
    align: 'center',
  },
  {
    title: '超级审核员',
    dataIndex: 'super_auditor_name',
    width: 100,
    align: 'center',
  },
  {
    title: '任务修改时间',
    dataIndex: 'update_time',
    width: 180,
    align: 'center',
  },
  {
    title: '任务状态',
    dataIndex: 'status',
    width: 100,
    align: 'center',
    customRender: ({ record }) => {
      const status = record.status;
      const color = status===0 ? 'green' : 'red';
      const text = status===0 ? '开启' : '关闭';
      return h(Tag, { color: color }, () => text);
    },
  },
  {
    title: '备注',
    dataIndex: 'tips',
    width: 160,
    align: 'center',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'id',
    label: '任务ID',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'title',
    label: '任务标题',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'task_type',
    label: '任务类型',
    component: 'ApiSelect',
    componentProps: {
      api: DicItem,
      params: { item: 'taskType' },
      labelField: 'name',
      valueField: 'id',
    },
    colProps: { span: 8 },
  },
  {
    field: 'auditor_id',
    label: '审核员',
    component: 'ApiSelect',
    componentProps: {
      api: getAccountNameList,
      params: { },
      labelField: 'real_name',
      valueField: 'user_id',
    },
    colProps: { span: 8 },
  },
  {
    field: 'status',
    label: '任务状态',
    component: 'Select',
    defaultValue: 0,
    componentProps: {
      options: [
        { label: '开启', value: 0 },
        { label: '关闭', value: 1 },
      ],
    },
    colProps: { span: 8 },
  },
];

//新增弹窗form字段
export const formSchema: FormSchema[] = [
  {
    label: 'ID',
    field: 'id',
    component: 'Input',
    defaultValue: 0,
    show: false,
  },
  {
    label: '任务类型',
    field: 'task_type',
    component: 'ApiSelect',
    componentProps: {
      api: DicItem,
      params: { item: 'taskType' },
      labelField: 'name',
      valueField: 'id',
    },
    required: true,
  },
  {
    field: 'title',
    label: '任务标题',
    component: 'Input',
    required: true,
  },
  {
    field: 'reward',
    label: '奖励点数',
    component: 'InputNumber',
    required: true,
  },
  {
    label: '奖励单位',
    field: 'reward_unit',
    component: 'Input',
    required: false,
  },
  {
    label: '审核员',
    field: 'auditor_id',
    component: 'ApiSelect',
    componentProps: {
      api: getAccountNameList,
      params: { },
      labelField: 'real_name',
      valueField: 'user_id',
    },
    required: true,
  },
  {
    label: '二次审核员id',
    field: 'super_auditor_id',
    component: 'ApiSelect',
    componentProps: {
      api: getAdminUserNameList,
      params: { },
      labelField: 'real_name',
      valueField: 'user_id',
    },
    required: true,
  },
  {
    field: 'tips',
    label: '备注',
    component: 'InputTextArea',
    defaultValue: '',
    show: false,
  },
  {
    field: 'status',
    label: '是否开启任务',
    component: 'RadioButtonGroup',
    defaultValue: 0,
    componentProps: {
      options: [
        { label: '开启', value: 0 },
        { label: '关闭', value: 1 },
      ],
    },
    required: true,
  },
];
